package org.opencv;

import android.content.Context;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class OpenCVSDKTest {
    private static final String TAG = "OpenCVSDK";
    private static final OpenCVSDKTest ourInstance = new OpenCVSDKTest();

    public static OpenCVSDKTest getInstance() {
        return ourInstance;
    }

    private OpenCVSDKTest() {
    }

    public void run(Context context, String str, String str2, String str3, int i) {
        Exception e;
        try {
            Mat imread = Imgcodecs.imread(str);
            Mat imread2 = Imgcodecs.imread(str2);
            System.currentTimeMillis();
            for (int i2 = 0; i2 < i; i2++) {
                try {
                    Mat mat = new Mat((imread.rows() - imread2.rows()) + 1, (imread.cols() - imread2.cols()) + 1, CvType.CV_32FC1);
                    Imgproc.matchTemplate(imread, imread2, mat, 3);
                    int i3 = 0;
                    int i4 = 0;
                    for (int i5 = 0; i5 < mat.rows(); i5++) {
                        for (int i6 = 0; i6 < mat.cols(); i6++) {
                            if (mat.get(i5, i6)[0] > 0.9d && Math.abs(i5 - i3) > 5 && Math.abs(i6 - i4) > 5) {
                                Imgproc.rectangle(imread, new Point((double) i6, (double) i5), new Point((double) (imread2.cols() + i6), (double) (imread2.rows() + i5)), new Scalar(0.0d, 255.0d, 0.0d));
                                try {
                                    Imgcodecs.imwrite(str3, imread);
                                    i3 = i5;
                                    i4 = i6;
                                } catch (Exception e2) {
                                    e = e2;
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                } catch (Exception e3) {
                    e = e3;
                    e.printStackTrace();
                }
            }
        } catch (Exception e4) {
            e4.printStackTrace();
        }
    }

    public void setPicLike(Context context, int i) {
        context.getSharedPreferences("VoiceData_1", 0).edit().putInt("setPicLike", i).commit();
    }

    public int getPicLike(Context context) {
        return context.getSharedPreferences("VoiceData_1", 0).getInt("setPicLike", 90);
    }
}
